<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<input type="text" id="i1">
<input type="button" value="平方" onclick="f1()">
<div>结果:<span></span></div>

<script>
  function f1(){
    let l = document.querySelector("#i1");
    let s = document.querySelector("span");
    /*isNaN()判断变量是否是一个字符*/
    if(isNaN(l.value)){
      s.innerText = "输入错误!";
      return;
    }
    /*当两个字符串进行+运算时是拼接 其他会自动转为数值*/
    // s.innerText = l.value*l.value;
    // s.innerText = l.value*1+l.vlaue*1;
    /*将字符串转换为float 或者 int类型*/
    s.innerText = parseFloat(l.value)+parseInt(l.value);
    console.log(s);
  }
</script>

</body>
</html>